<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var obj = {
            id:1,
            name:'andy',
            msg:{
                age:18
            },
            color:['pink','red']
        };
        var o={};
        
        function deepCopy(newobj,oldobj){
            for(var k in oldobj){
                var item = oldobj[k];
                if(item instanceof Array){
                    newobj[k] = [];
                    deepCopy(newobj[k],item);
                }else if(item instanceof Object){
                    newobj[k]={};
                    deepCopy(newobj[k],item);
                }else{
                    newobj[k]=item;
                }
            }
        }
        deepCopy(o,obj);
        console.log(o);

    </script>
</body>
</html>